package com.ruoyi.business.base.controller;

import com.ruoyi.business.base.domain.AssetType;
import com.ruoyi.business.base.service.IAssetTypeService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.plugins.Docket;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资产类别Controller
 *
 * @author lcy
 * @date 2024-09-24
 */
@RestController
@RequestMapping("/base/assetType")
@Api(tags = "资产类别相关接口")
public class AssetTypeController extends BaseController {

    @Autowired
    private IAssetTypeService assetTypeService;
    @Autowired
    private Docket api;

    /**
     * 查询资产类别列表
     */
    @RequiresPermissions("base:assetType:list")
    @GetMapping("/list")
    @Log(value = "查询资产类别列表")
    @ApiOperation("查询资产类别列表")
    public AjaxResult list(AssetType assetType) {
        List<AssetType> list = assetTypeService.selectAssetTypeList(assetType);
        return success(list);
    }

    /**
     * 查询资产类别树列表
     */
    @RequiresPermissions("base:assetType:list")
    @GetMapping("/assetTypeTree")
    @ApiOperation("查询资产类别树列表")
    @Log(value = "查询资产类别树列表")
    public AjaxResult assetTypeTree(AssetType assetType)
    {
        return success(assetTypeService.selectAssetTypeTreeList(assetType));
    }

    /**
     * 导出资产类别列表
     */
    @RequiresPermissions("base:assetType:export")
    @Log(title = "资产类别", businessType = BusinessType.EXPORT,value = "导出资产类别列表")
    @PostMapping("/export")
    @ApiOperation("导出资产类别列表")
    public void export(HttpServletResponse response, AssetType assetType) {
        List<AssetType> list = assetTypeService.selectAssetTypeList(assetType);
        ExcelUtil<AssetType> util = new ExcelUtil<AssetType>(AssetType.class);
        util.exportExcel(response, list, "资产类别数据");
    }

    /**
     * 获取资产类别详细信息
     */
    @RequiresPermissions("base:assetType:query")
    @GetMapping(value = "/{id}")
    @Log(value = "查询资产类别详细信息")
    @ApiOperation("获取资产类别详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(assetTypeService.selectAssetTypeById(id));
    }

    /**
     * 新增资产类别
     */
    @RequiresPermissions("base:assetType:add")
    @Log(title = "资产类别", businessType = BusinessType.INSERT,value = "新增资产类别")
    @PostMapping("/insert")
    @ApiOperation("新增资产类别")
    public AjaxResult add(@RequestBody AssetType assetType) {
        return toAjax(assetTypeService.insertAssetType(assetType));
    }

    /**
     * 修改资产类别
     */
    @RequiresPermissions("base:assetType:edit")
    @Log(title = "资产类别", businessType = BusinessType.UPDATE,value = "修改资产类别")
    @PutMapping("/update")
    @ApiOperation("修改资产类别")
    public AjaxResult edit(@RequestBody AssetType assetType) {
        return toAjax(assetTypeService.updateAssetType(assetType));
    }

    /**
     * 删除资产类别
     */
    @RequiresPermissions("base:assetType:remove")
    @Log(title = "资产类别", businessType = BusinessType.DELETE,value = "删除资产类别")
	@DeleteMapping("/delete/{ids}")
    @ApiOperation("删除资产类别")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(assetTypeService.deleteAssetTypeByIds(ids));
    }
}
